{% if setting('magic.enable_org', '0') %}
  {% set modal = modal|default(null) %}

  {% if modal == 'modal' %}
    <script>app.load('topxiaadminbundle/controller/widget/category-select')</script>
  {% else %}
    {% do load_script('topxiaadminbundle/controller/widget/category-select') %}
  {% endif %}

  <style>
    .tree-select {
      min-width: 120px;
    }
  </style>

  {% set colmd = colmd|default(8) %}
  {% set lablecolmd = lablecolmd|default(2) %}
  {% set nocolmd = nocolmd|default(false) %}
  {% set inputClass = inputClass|default('') %}

  {% set currentOrgCode = orgCode|default(app.user.orgCode) %}
  {% set currentOrgTree = data('OrgTree',{orgCode: ('ROLE_SUPER_ADMIN' in app.user.roles) ? null : currentOrgCode }) %}

    <div class="form-group {% if modal == 'list' %}controls{% endif %}">
      {% if modal != 'list' %}
      <label class="{% if not nocolmd %} col-md-{{lablecolmd}}{% endif %} control-label">{{'site.org'|trans}}</label>
      <div class="{% if not nocolmd %} col-md-{{colmd}} {% endif %}  controls">
      {% endif %}

      <select data-role="tree-select" name="orgCode" class="form-control tree-select {{inputClass}}">
        <option value={{ currentOrgTree.0.orgCode }}>{{ currentOrgTree.0.name }}</option>
        {% for org in currentOrgTree %}
          <option value={{ org.orgCode }} {% if org.orgCode == currentOrgCode  %}selected{% endif %}>{% for i in 1..(org.depth-1) if org.depth > 1 %}　{% endfor %}{{ org.name }}</option>
        {% endfor %}
      </select>

      {% if modal != 'list' %}
      </div>
      {% endif %}
    </div>
 {% endif %}
